#include <GameEngine/Graphics/Meshes/indexed_mesh_primitives.h>


#ifdef GAMEENGINE_NAMESPACES
namespace GameEngine {
#endif


//==========================================================================


//! Default constructor
IndexedTrgl::IndexedTrgl() :
	index1_(0), index2_(0), index3_(0),
	coords_(false), cindex1_(0), cindex2_(0), cindex3_(0),
	normals_(false), nindex1_(0), nindex2_(0), nindex3_(0)
{}

//! Copy constructor
/*!
 @param rhs The indexed triangle to copy
 */
IndexedTrgl::IndexedTrgl(const IndexedTrgl& rhs) :
	index1_(rhs.index1_), index2_(rhs.index2_), index3_(rhs.index3_),
	coords_(rhs.coords_), cindex1_(rhs.cindex1_), cindex2_(rhs.cindex2_), cindex3_(rhs.cindex3_),
	normals_(rhs.normals_), nindex1_(rhs.nindex1_), nindex2_(rhs.nindex2_), nindex3_(rhs.nindex3_) {}

//! Assignment operator
/*!
 @param rhs The indexed triangle to copy
 @return A reference to this indexed triangle
 */
IndexedTrgl& IndexedTrgl::operator=(const IndexedTrgl& rhs) {
	if ( &rhs != this ) {
		index1_ = rhs.index1_;
		index2_ = rhs.index2_;
		index3_ = rhs.index3_;
		coords_ = rhs.coords_;
		cindex1_ = rhs.cindex1_;
		cindex2_ = rhs.cindex2_;
		cindex3_ = rhs.cindex3_;
		normals_ = rhs.normals_;
		nindex1_ = rhs.nindex1_;
		nindex2_ = rhs.nindex2_;
		nindex3_ = rhs.nindex3_;
	}
	return *this;
}

//! Destructor
IndexedTrgl::~IndexedTrgl() {}

//! Set given point to the given vertex index
/*!
 @param point The point to change. This value should be 0 for point 1, 1 for point
              2 and 2 for point 3. Any other value will be ignored.
 @param index The new vertex index of this point
 */
void IndexedTrgl::set_index(int point, SurfaceMesh::VertexIndex index) {
	if ( point == 0 ) index1_ = index;
	else if ( point == 1 ) index2_ = index;
	else if ( point == 2 ) index3_ = index;
}

//! Set given point to the given texture coordinate index
/*!
 @param point The point to change. This value should be 0 for point 1, 1 for point
              2 and 2 for point 3. Any other value will be ignored.
 @param index The new texture coordinate index of this point
 @note The texture coordinates must be defined as "used" separately, using the
       use_texture_coordinates() function.
 */
void IndexedTrgl::set_cindex(int point, SurfaceMesh::TextureCoordinateIndex index) {
	if ( point == 0 ) cindex1_ = index;
	else if ( point == 1 ) cindex2_ = index;
	else if ( point == 2 ) cindex3_ = index;
}

//! Set given point to the given normal index
/*!
 @param point The point to change. This value should be 0 for point 1, 1 for point
              2 and 2 for point 3. Any other value will be ignored.
 @param index The new normal index of this point
 @note The normals must be defined as "used" separately, using the use_normals() function.
 */
void IndexedTrgl::set_nindex(int point, SurfaceMesh::NormalIndex index) {
	if ( point == 0 ) nindex1_ = index;
	else if ( point == 1 ) nindex2_ = index;
	else if ( point == 2 ) nindex3_ = index;
}

//! Accessor to the vertex index of the first point of the triangle (read only)
/*!
 @return The vertex index associated to the first point of the triangle
 */
SurfaceMesh::VertexIndex IndexedTrgl::index1() const {
	return index1_;
}

//! Accessor to the vertex index of the first point of the triangle (read-write)
/*!
 @return A reference to the vertex index associated to the first point of the triangle
 */
SurfaceMesh::VertexIndex& IndexedTrgl::index1() {
	return index1_;
}

//! Accessor to the vertex index of the second point of the triangle (read only)
/*!
 @return The vertex index associated to the second point of the triangle
 */
SurfaceMesh::VertexIndex IndexedTrgl::index2() const {
	return index2_;
}

//! Accessor to the vertex index of the second point of the triangle (read-write)
/*!
 @return A reference to the vertex index associated to the second point of the triangle
 */
SurfaceMesh::VertexIndex& IndexedTrgl::index2() {
	return index2_;
}

//! Accessor to the vertex index of the third point of the triangle (read only)
/*!
 @return The vertex index associated to the third point of the triangle
 */
SurfaceMesh::VertexIndex IndexedTrgl::index3() const {
	return index3_;
}

//! Accessor to the vertex index of the third point of the triangle (read-write)
/*!
 @return A reference to the vertex index associated to the third point of the triangle
 */
SurfaceMesh::VertexIndex& IndexedTrgl::index3() {
	return index3_;
}

//! Change the use of texture coordinates
/*!
 @param use Define if the triangle uses texture coordinates (true) or not (false)
 */
void IndexedTrgl::use_texture_coordinates(bool use) {
	coords_ = use;
}

//! Test if the triangle uses texture coordinates
/*!
 @return True if the triangle uses texture coordinates, false otherwise
 */
bool IndexedTrgl::has_texture_coordinates() const {
	return coords_;
}

//! Accessor to the texture coordinates index of the first point of the triangle (read only)
/*!
 @return The texture coordinates index associated to the first point of the triangle
 */
SurfaceMesh::TextureCoordinateIndex IndexedTrgl::cindex1() const {
	return cindex1_;
}

//! Accessor to the texture coordinates index of the first point of the triangle (read-write)
/*!
 @return A reference to the texture coordinates index associated to the first point of the triangle
 */
SurfaceMesh::TextureCoordinateIndex& IndexedTrgl::cindex1() {
	return cindex1_;
}

//! Accessor to the texture coordinates index of the second point of the triangle (read only)
/*!
 @return The texture coordinates index associated to the second point of the triangle
 */
SurfaceMesh::TextureCoordinateIndex IndexedTrgl::cindex2() const {
	return cindex2_;
}

//! Accessor to the texture coordinates index of the second point of the triangle (read-write)
/*!
 @return A reference to the texture coordinates index associated to the second point of the triangle
 */
SurfaceMesh::TextureCoordinateIndex& IndexedTrgl::cindex2() {
	return cindex2_;
}

//! Accessor to the texture coordinates index of the third point of the triangle (read only)
/*!
 @return The texture coordinates index associated to the third point of the triangle
 */
SurfaceMesh::TextureCoordinateIndex IndexedTrgl::cindex3() const {
	return cindex3_;
}

//! Accessor to the texture coordinates index of the third point of the triangle (read-write)
/*!
 @return A reference to the texture coordinates index associated to the third point of the triangle
 */
SurfaceMesh::TextureCoordinateIndex& IndexedTrgl::cindex3() {
	return cindex3_;
}

//! Change the use of normals
/*!
 @param use Define if the triangle uses normals (true) or not (false)
 */
void IndexedTrgl::use_normals(bool use) {
	normals_ = use;
}

//! Test if the triangle uses normals
/*!
 @return True if the triangle uses normals, false otherwise
 */
bool IndexedTrgl::has_normals() const {
	return normals_;
}

//! Accessor to the normal index of the first point of the triangle (read only)
/*!
 @return The normal index associated to the first point of the triangle
 */
SurfaceMesh::NormalIndex IndexedTrgl::nindex1() const {
	return nindex1_;
}

//! Accessor to the normal index of the first point of the triangle (read-write)
/*!
 @return A reference to the normal index associated to the first point of the triangle
 */
SurfaceMesh::NormalIndex& IndexedTrgl::nindex1() {
	return nindex1_;
}

//! Accessor to the normal index of the second point of the triangle (read only)
/*!
 @return The normal index associated to the second point of the triangle
 */
SurfaceMesh::NormalIndex IndexedTrgl::nindex2() const {
	return nindex2_;
}

//! Accessor to the normal index of the second point of the triangle (read-write)
/*!
 @return A reference to the normal index associated to the second point of the triangle
 */
SurfaceMesh::NormalIndex& IndexedTrgl::nindex2() {
	return nindex2_;
}

//! Accessor to the normal index of the third point of the triangle (read only)
/*!
 @return The normal index associated to the third point of the triangle
 */
SurfaceMesh::NormalIndex IndexedTrgl::nindex3() const {
	return nindex3_;
}

//! Accessor to the normal index of the third point of the triangle (read-write)
/*!
 @return A reference to the normal index associated to the third point of the triangle
 */
SurfaceMesh::NormalIndex& IndexedTrgl::nindex3() {
	return nindex3_;
}


//==========================================================================


#ifdef GAMEENGINE_NAMESPACES
} // namespace GameEngine
#endif
